// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLExprImpl;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.ast.SQLReplaceable;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.Collections;
// import java.util.List;

#include "OracleOuterExpr.h"
#include "../../../../ast/SQLExpr.h"
#include "../../../../ast/SQLObject.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"
#include "../../../../../utils/instanceof.h"

OracleOuterExpr::OracleOuterExpr()
{
}

OracleOuterExpr::OracleOuterExpr(SQLExpr_ptr expr)
{
  this->expr = expr;
}

SQLObject_ptr OracleOuterExpr::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleOuterExpr>(new OracleOuterExpr());
  std::shared_ptr<OracleOuterExpr> x = std::dynamic_pointer_cast<OracleOuterExpr>(clone_tmp);
  // OracleOuterExpr x = new OracleOuterExpr();
  if (expr != nullptr)
  {
    x->setExpr(std::dynamic_pointer_cast<SQLExpr>(expr->clone()));
  }
  return x;
}

SQLExpr_ptr OracleOuterExpr::getExpr()
{
  return this->expr;
}

void OracleOuterExpr::setExpr(SQLExpr_ptr expr)
{
  this->expr = expr;
}

// @Override
BOOL_ptr OracleOuterExpr::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (this->expr == expr)
  {
    setExpr(target);
    return BOOL::TRUE;
  }
  return BOOL::FALSE;
}

// @Override
void OracleOuterExpr::accept0(SQLASTVisitor_ptr visitor)
{
  if (instanceof <SQLASTVisitor, OracleASTVisitor>(visitor))
  {
    this->accept0(std::dynamic_pointer_cast<OracleASTVisitor>(visitor));
  }
  else
  {
    acceptChild(visitor, this->expr);
  }
}

void OracleOuterExpr::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleOuterExpr)))
  {
    acceptChild(visitor, this->expr);
  }

  visitor->endVisit(SharedObject(OracleOuterExpr));
}

// @Override
SQLObject_list_ptr OracleOuterExpr::getChildren()
{
  SQLObject_list_ptr tmp = std::make_shared<std::list<SQLObject_ptr>>();
  tmp->push_back(this->expr);
  return tmp;
}

// @Override
int OracleOuterExpr::hashCode()
{
  int prime = 31;
  int result = 1;
  result = prime * result + ((expr == nullptr) ? 0 : expr->hashCode());
  return result;
}

// @Override
bool OracleOuterExpr::equals(Object_ptr obj)
{
  if (this == obj.get())
  {
    return true;
  }
  if (obj == nullptr)
  {
    return false;
  }
  if (getClass()->c_str() != obj->getClass()->c_str())
  {
    return false;
  }
  OracleOuterExpr_ptr other = std::dynamic_pointer_cast<OracleOuterExpr>(obj);
  if (expr == nullptr)
  {
    if (other->expr != nullptr)
    {
      return false;
    }
  }
  else if (!expr->equals(other->expr))
  {
    return false;
  }
  return true;
}
